package com.scs.application.modules.base.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.scs.application.core.exception.BusinessException;
import com.scs.application.modules.base.entity.PackTemplet;
import com.scs.application.modules.base.entity.PackType;
import com.scs.application.modules.base.mapper.PackTypeMapper;
import com.scs.application.modules.base.service.PackTempletService;
import com.scs.application.modules.base.service.PackTypeService;
import com.scs.application.core.service.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 */
@Service
public class PackTypeServiceImpl extends BaseServiceImpl<PackTypeMapper, PackType> implements PackTypeService {

    @Autowired
    private PackTempletService packTempletService;
    @Override
    public boolean removeCascadeByIds(Collection<? extends Serializable> idList) {

        List<String> packTempletIds = packTempletService.listObjs(Wrappers.<PackTemplet>query()
                        .select("id" ).in("pack_type_id" , idList).groupBy("id"),
                v -> v.toString());

        if (packTempletIds.size() > 0) {
            throw new BusinessException("已有绑定的模板，不允许删除");
        }

        return super.removeCascadeByIds(idList);
    }
}
